package com.example.jetpackcomposelazycolumn

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import com.example.jetpackcomposelazycolumn.data.paging.PostPagingDataSource


class ImagePagingViewModel : ViewModel() {

    val post =  Pager (PagingConfig(
            // 每页显示的数据的大小。对应 PagingSource 里 LoadParams.loadSize
            pageSize = 20,

            // 预刷新的距离，距离最后一个 item 多远时加载数据，默认为 pageSize
            prefetchDistance = 5,

            enablePlaceholders = false,

            // 初始化加载数量，默认为 pageSize * 3
            initialLoadSize = 60,

            // 一次应在内存中保存的最大数据，默认为 Int.MAX_VALUE
            maxSize = 200
        )) {
            PostPagingDataSource()
        }.flow.cachedIn(viewModelScope)
}